<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="row">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">江苏安纳泰克售电套餐</h3>
                </div>
                <div class="panel-body">
                        <div class="tab-base tab-stacked-left">
                            <ul class="nav nav-tabs" style="width:150px">
                                <li class="active" style="width:150px">
                                    <a data-toggle="tab" href="#demo-stk-lft-tab-1">
                                        <p>套餐A</p>
                                        <p>一九分成</p>
                                    </a>
                                </li>
                                <!--<li style="width:150px">
                                    <a data-toggle="tab" href="#demo-stk-lft-tab-2">
                                        <p>套餐B</p>
                                        <p>100%全返</p>
                                    </a>
                                </li>-->
                                <li style="width:150px">
                                    <a data-toggle="tab" href="#demo-stk-lft-tab-3">
                                        <p>自定义套餐</p>
                                        <p>&nbsp;</p>
                                    </a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <#include "choose_a.ftl"/>
                                <#include "choose_b.ftl"/>
                                <#include "choose_c.ftl"/>
                                <input type="hidden" name="companyId" id="companyId" value="${companyInfo.id}"/>
                                <input type="hidden" name="contractInfoId" id="contractInfoId" value="${(contractInfo.id)!}"/>
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </#if>
    <#if part="modal">
    </#if>

    <#if part="foot_script">
    <script src="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.js"/>"></script>
    <script type="text/javascript">

        $("#bd_btn").click(function(){
            $("#bd_btn").addClass("active");
            $("#fc_btn").removeClass("active");
            $("#bd_div").show();
            $("#fc_div").hide();
        });
        $("#fc_btn").click(function(){
            $("#fc_btn").addClass("active");
            $("#bd_btn").removeClass("active");
            $("#bd_div").hide();
            $("#fc_div").show();
        });
        function saveMoney(tab) {
            var elec_num = $("#elec_num_"+tab).val();
            if ($.trim(elec_num) == "") {
                alert("请填入全年用电量。");
                return false;
            }
            if (isNaN(elec_num)) {
                alert("全年用电量请填入1-99之间的数字。");
                return false;
            }
            if (tab == "a") {
                var price = Math.round((2.18*0.7+0.3*1.6)*parseFloat(elec_num)*10000*0.9)/100;
                $("#money_a").val(price);
            } else if (tab == "b") {
                var save_price = Math.round((2.18*0.7+0.3*1.6)*parseFloat(elec_num)*10000)/100;
                var server_price = Math.round((2.18*0.7+0.3*1.6)*3000000*0.2/100)/100;
                $("#money_b").val(save_price);
                $("#server_money_b").html(server_price);
            } else if (tab == "c1") {
                var customer_percent = $("#customer_percent").val();
                if ($.trim(customer_percent) == "") {
                    alert("请填入客户分成比例。");
                    return false;
                }
                if (isNaN(customer_percent) || parseFloat(customer_percent)<1 || parseFloat(customer_percent)>99) {
                    alert("客户分成比例请填入1-99之间的数字。");
                    return false;
                }
                var price = Math.round((2.18*0.7+0.3*1.6)*parseFloat(elec_num)*10000*parseFloat(customer_percent)/100)/100;
                $("#money_c1").val(price);
            } else if (tab == "c2") {
                var base_price = $("#base_price").val();
                if ($.trim(base_price) == "" || isNaN(base_price)) {
                    alert("请填入保底价格，并为数字类型。");
                    return false;
                }
                /*var month_percent = $("#month_percent").val();
                if ($.trim(month_percent) == "") {
                    alert("请填入月度分成比例。");
                    return false;
                }
                if (isNaN(month_percent) || parseFloat(month_percent)<1 || parseFloat(month_percent)>99) {
                    alert("月度分成比例请填入1-99之间的数字。");
                    return false;
                }*/
                var price = Math.round((parseFloat(base_price)*0.7+0.3*1.6*parseFloat(0.7)/100)*parseFloat(elec_num)*10000)/100;
                $("#money_c2").val(price);
            }

        }

        function getOld(tab) {
                var old_e = $("#old_"+tab).html();
                if (old_e != null && old_e != undefined && $.trim(old_e) != "") {
                    $("#elec_num_"+tab).val(old_e);
                }
        }

        function chooseType(types) {
            var tab = "c2";
            if (types == 1){
                tab = "a";
            } else if (types == 2) {
                tab = "b";
            } else if (types == 3) {
                tab = "c1";
            }
            var elec_num = $("#elec_num_"+tab).val();
            if ($.trim(elec_num) == "") {
                alert("请填入全年用电量。");
                return false;
            }
            if (isNaN(elec_num)) {
                alert("全年用电量请填入数字。");
                return false;
            }
            var companyId = $("#companyId").val();
            var contractInfoId = $("#contractInfoId").val();
            var comment = $("#comment_"+types).val();
            var customer_percent = null;
            var base_price = null;
            var month_percent = null;

            if (types == 3) {
                customer_percent = $.trim($("#customer_percent").val());
                if ($.trim(customer_percent) == "") {
                    alert("请填入客户分成比例。");
                    return false;
                }
                if (isNaN(customer_percent) || parseFloat(customer_percent)<1 || parseFloat(customer_percent)>99) {
                    alert("客户分成比例请填入1-99之间的数字。");
                    return false;
                }
            } else  if (types == 4) {
                base_price = $.trim($("#base_price").val());
                //month_percent = $.trim($("#month_percent").val());
                if ($.trim(base_price) == "" || isNaN(base_price)) {
                    alert("请填入保底价格，并为数字类型。");
                    return false;
                }
                /*if ($.trim(month_percent) == "") {
                    alert("请填入月度分成比例。");
                    return false;
                }
                if (isNaN(month_percent) || parseFloat(month_percent)<1 || parseFloat(month_percent)>99) {
                    alert("月度分成比例请填入1-99之间的数字。");
                    return false;
                }*/

            } else if (types == 2) {
                customer_percent = 100;
            } else {
                customer_percent = 90;
            }
            var trade_cycle = $("#trade_cycle_"+tab).val();
            if ($.trim(trade_cycle) == "" || isNaN(trade_cycle)) {
                alert("请填入交易周期，并为数字类型。");
                return false;
            }
            if (confirm("确定选择当前套餐吗？")){
                $.post("<@spring.url "/contractInfo/update"/>",{
                    companyId:companyId, contractInfoId:contractInfoId, types:types,
                    estElecConsumption:elec_num, description:comment, longAgreementRate:customer_percent,
                    bottomPrice:base_price, baseRate1:month_percent, tradeCycle:trade_cycle
                }, function (data) {
                    if (data.code == 1) {
                        alert("售电套餐选择成功,我们的工作人员将在24小时内联系您。");
                        window.location.href="<@spring.url "/index"/>";
                    } else {
                        alert(data.message);
                    }

                });
            }
        }

    </script>
    </#if>
</@t.html>